public class ImageFormatConverter implements Converter {
    @Override
    public boolean support(FileFormat sourceFormat, FileFormat targetFormat) {
        return isImage(sourceFormat) && isImage(targetFormat);
    }
    
    private boolean isImage(FileFormat format) {
        return format == FileFormat.JPG || format == FileFormat.PNG || 
               format == FileFormat.GIF || format == FileFormat.BMP;
    }
    
    @Override
    public void convert(File source, File target, ConversionConfig config) throws ConversionException {
        try {
            if (!source.exists()) {
                throw new FileOperationException("源文件不存在: " + source.getPath());
            }
            
            BufferedImage sourceImage = ImageIO.read(source);
            if (sourceImage == null) {
                throw new FileOperationException("无法读取图片文件: " + source.getPath());
            }
            
            String formatName = target.getName().substring(target.getName().lastIndexOf('.') + 1);
            if (!ImageIO.write(sourceImage, formatName, target)) {
                throw new FileOperationException("无法写入目标文件: " + target.getPath());
            }
        } catch (IOException e) {
            throw new FileOperationException("图片转换过程中发生错误", e);
        }
    }
} 